home *** CD-ROM | disk | FTP | other *** search
- Path: news.infi.net!usenet
- From: nngis@norfolk.infi.net (Greg DiGiorgio)
- Newsgroups: comp.lang.c,alt.msdos.programmer
- Subject: Re: Two strange C problems.
- Date: 9 Jan 1996 13:22:49 GMT
- Organization: Customer of InfiNet
- Distribution: world
- Message-ID: <4ctq79$27l@news.infi.net>
- References: <4cojb2$qog@lugb.latrobe.edu.au>
- Reply-To: nngis@norfolk.infi.net
- NNTP-Posting-Host: h-overdrive.norfolk.infi.net
- Mime-Version: 1.0
- X-Newsreader: WinVN 0.99.3
-
- In article <4cojb2$qog@lugb.latrobe.edu.au>, cs102238@lux.latrobe.edu.au
- says...
- >
- >I have two C problems.
- >
-
- For time's sake, I am not replying to the first problem...
-
- >
- >PROBLEM 2 :
- >
- >const escape=27;
- >const cr=13;
- >const bs=8;
- >
- >while (ch!=cr)
- >{
- > .
- > .
- > .
- >}
- >
- >while (ch!=escape)
- >{
- > .
- > .
- > .
- >}
- >
- >If I replace the 27 with \27' or the 13 with '\13' then these loops
- don't
- >work i.e. an infinite loop results. WHY?
-
- Because the following line:
-
- int ch = '\27';
-
- is in Octal. That is, '\27' specifies an octal value, not decimal. So the
- '27' is in base 8 and ends up being actually 23 in base 10 - not what you
- expect. 'C' has built-in "escape sequences" for most of what you want:
-
- int ch = '\n'; /* new line */
-
- For the escape char, convert to hexadecimal and use:
-
- int ch = '\x17'; /* This is 27 decimal */
-
-
- >
- >Also if I want to do somthing like this : puts("\24 \25"); which should
- >print the up and down arrows on the screen (ASCII 24 and 25), but no, it
- >prints some other ASCII characters. As far as I can tell C has its own
- >unique character table, at least for the control characters. WHY?
-
- Same reason here...
-
- >
- >Sometimes I wonder whether some one needs to go back an rewrite the damn
- >language so that it works sensibly and predictably like Pascal can be
- >relied upon to do.
-
- When I first started in 'C' programming in 1988, I too took solace in my
- knowledge of Pascal - which was the dominant teaching language when I was
- in college. In fact, when I came to a shop where 'C' was king, I
- continued programming my projects in Pascal. But as I learned 'C' and
- felt comfortable with the language, I shucked Pascal in a hurry. You just
- can not do many things in Pascal as simply as you can in 'C'.
-
- True, Pascal has some great abstract data types like "sets", but for my
- money, I'll take 'C'. Plus, most commercial developers use 'C', not
- Pascal. Plus, UNIX OS's come with (sometime its optional) a 'C' compiler,
- not Pascal. Plus, UNIX was written in 'C', Plus, Windows is written in
- 'C'. Plus, the only Pascal that is even remotely popular is Delphi and
- it only works in Windows. But if you choose 'C', you have a choice of
- vendors and platforms.
-
- Hope this helps some,
- Greg DiGiorgio
-
-